
<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8">
        <title>浏览页面</title>
        <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
        <link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
    </head>
    <body class="pear-container">
    
        <!-- 顶部查询表单 -->
        
        
        <!-- 数据表格 -->
        <div class="layui-card">
            <div class="layui-card-body">
                <table id="data-table" lay-filter="data-table"></table>
            </div>
        </div>

        <!-- 表格顶部工具栏 -->
        <script type="text/html" id="table-toolbar">
            <button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add" permission="app.admin.tejianonecardorder.insert">
                <i class="layui-icon layui-icon-add-1"></i>新增
            </button>
            <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove" permission="app.admin.tejianonecardorder.delete">
                <i class="layui-icon layui-icon-delete"></i>删除
            </button>
        </script>

        <!-- 表格行工具栏 -->
        <script type="text/html" id="table-bar">
            <button class="pear-btn pear-btn-xs tool-btn" lay-event="edit" permission="app.admin.tejianonecardorder.update">编辑</button>
            <button class="pear-btn pear-btn-xs tool-btn" lay-event="remove" permission="app.admin.tejianonecardorder.delete">删除</button>
        </script>

        <script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
        <script src="/app/admin/component/pear/pear.js"></script>
        <script src="/app/admin/admin/js/permission.js"></script>
        <script src="/app/admin/admin/js/common.js"></script>
        
        <script>

            // 相关常量
            const PRIMARY_KEY = "id";
            const SELECT_API = "/app/admin/tejian-onecard-order/select";
            const UPDATE_API = "/app/admin/tejian-onecard-order/update";
            const DELETE_API = "/app/admin/tejian-onecard-order/delete";
            const INSERT_URL = "/app/admin/tejian-onecard-order/insert";
            const UPDATE_URL = "/app/admin/tejian-onecard-order/update";
            
            // 表格渲染
            layui.use(["table", "form", "common", "popup", "util"], function() {
                let table = layui.table;
                let form = layui.form;
                let $ = layui.$;
                let common = layui.common;
                let util = layui.util;
                
				// 表头参数
				let cols = [
					{
						type: "checkbox",
						align: "center"
					},{
						title: "订单ID",align: "center",
						field: "id",
					},{
						title: "mall_id",align: "center",
						field: "mall_id",
					},{
						title: "mch_id",align: "center",
						field: "mch_id",
					},{
						title: "订单流水号",align: "center",
						field: "order_no",
					},{
						title: "一卡通商品ID",align: "center",
						field: "onecard_id",
					},{
						title: "一卡通商品名称",align: "center",
						field: "onecard_name",
					},{
						title: "年卡发行批次",align: "center",
						field: "batch_id",
					},{
						title: "状态:0=待支付,1=已支付,2=已退款,3=已过期,4=退款审核中,5-用户已取消",align: "center",
						field: "status",
					},{
						title: "购买用户id",align: "center",
						field: "user_id",
					},{
						title: "下单用户IP",align: "center",
						field: "user_ip",
					},{
						title: "出行人id",align: "center",
						field: "contact_id",
					},{
						title: "购买的商品数量",align: "center",
						field: "product_count",
					},{
						title: "电子券短信密码",align: "center",
						field: "sms_pwd",
					},{
						title: "取消类型",align: "center",
						field: "cancel_type",
					},{
						title: "支付订单编号",align: "center",
						field: "pay_order_id",
					},{
						title: "是否已支付：[0:未支付 1:已经支付过]",align: "center",
						field: "pay_status",
					},{
						title: "下单日期",align: "center",
						field: "order_date",
					},{
						title: "支付平台支付订单号",align: "center",
						field: "out_trade_no",
					},{
						title: "订单支付时间",align: "center",
						field: "pay_time",
					},{
						title: "支付成功的支付渠道",align: "center",
						field: "pay_channel_code",
					},{
						title: "过期时间",align: "center",
						field: "expired_time",
					},{
						title: "订单取消时间",align: "center",
						field: "cancel_time",
					},{
						title: "退款时间",align: "center",
						field: "refund_time",
					},{
						title: "商品原价（总），单位：分",align: "center",
						field: "total_price",
					},{
						title: "订单优惠（总），单位：分",align: "center",
						field: "discount_price",
					},{
						title: "应付金额（总），单位：分",align: "center",
						field: "pay_price",
					},{
						title: "使用的优惠劵编号",align: "center",
						field: "coupon_id",
					},{
						title: "优惠劵减免金额，单位：分",align: "center",
						field: "coupon_price",
					},{
						title: "退款状态",align: "center",
						field: "refund_status",
					},{
						title: "退款说明",align: "center",
						field: "refund_remark",
					},{
						title: "退款金额，单位：分",align: "center",
						field: "refund_price",
					},{
						title: "创建者",align: "center",
						field: "creator",
					},{
						title: "创建时间",align: "center",
						field: "create_time",
					},{
						title: "更新者",align: "center",
						field: "updater",
					},{
						title: "更新时间",align: "center",
						field: "update_time",
					},{
						title: "是否删除",align: "center",
						field: "deleted",
					},{
						title: "租户编号",align: "center",
						field: "tenant_id",
					},{
						title: "商户订单核销状态：0-待核销；1-已核销；2-已确认；3-已退款",align: "center",
						field: "mer_order_state",
					},{
						title: "商户订单确认收货时间",align: "center",
						field: "mer_confirm_date",
					},{
						title: "商户订单确认信息",align: "center",
						field: "mer_order_msg",
					},{
						title: "操作",
						toolbar: "#table-bar",
						align: "center",
						fixed: "right",
						width: 120,
					}
				];
				
				// 渲染表格
				table.render({
				    elem: "#data-table",
				    url: SELECT_API,
				    page: true,
				    cols: [cols],
				    skin: "line",
				    size: "lg",
				    toolbar: "#table-toolbar",
				    autoSort: false,
				    defaultToolbar: [{
				        title: "刷新",
				        layEvent: "refresh",
				        icon: "layui-icon-refresh",
				    }, "filter", "print", "exports"],
				    done: function () {
				        layer.photos({photos: 'div[lay-id="data-table"]', anim: 5});
				    }
				});
				
				
                // 编辑或删除行事件
                table.on("tool(data-table)", function(obj) {
                    if (obj.event === "remove") {
                        remove(obj);
                    } else if (obj.event === "edit") {
                        edit(obj);
                    }
                });

                // 表格顶部工具栏事件
                table.on("toolbar(data-table)", function(obj) {
                    if (obj.event === "add") {
                        add();
                    } else if (obj.event === "refresh") {
                        refreshTable();
                    } else if (obj.event === "batchRemove") {
                        batchRemove(obj);
                    }
                });

                // 表格顶部搜索事件
                form.on("submit(table-query)", function(data) {
                    table.reload("data-table", {
                        page: {
                            curr: 1
                        },
                        where: data.field
                    })
                    return false;
                });
                
                // 表格顶部搜索重置事件
                form.on("submit(table-reset)", function(data) {
                    table.reload("data-table", {
                        where: []
                    })
                });
                
                // 字段允许为空
                form.verify({
                    phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"],
                    email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"],
                    url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"],
                    number: [/(^$)|^\d+$/,'只能填写数字'],
                    date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"],
                    identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"]
                });

                // 表格排序事件
                table.on("sort(data-table)", function(obj){
                    table.reload("data-table", {
                        initSort: obj,
                        scrollPos: "fixed",
                        where: {
                            field: obj.field,
                            order: obj.type
                        }
                    });
                });

                // 表格新增数据
                let add = function() {
                    layer.open({
                        type: 2,
                        title: "新增",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"500px", common.isModile()?"100%":"450px"],
                        content: INSERT_URL
                    });
                }

                // 表格编辑数据
                let edit = function(obj) {
                    let value = obj.data[PRIMARY_KEY];
                    layer.open({
                        type: 2,
                        title: "修改",
                        shade: 0.1,
                        maxmin: true,
                        area: [common.isModile()?"100%":"500px", common.isModile()?"100%":"450px"],
                        content: UPDATE_URL + "?" + PRIMARY_KEY + "=" + value
                    });
                }

                // 删除一行
                let remove = function(obj) {
                    return doRemove(obj.data[PRIMARY_KEY]);
                }

                // 删除多行
                let batchRemove = function(obj) {
                    let checkIds = common.checkField(obj, PRIMARY_KEY);
                    if (checkIds === "") {
                        layui.popup.warning("未选中数据");
                        return false;
                    }
                    doRemove(checkIds.split(","));
                }

                // 执行删除
                let doRemove = function (ids) {
                    let data = {};
                    data[PRIMARY_KEY] = ids;
                    layer.confirm("确定删除?", {
                        icon: 3,
                        title: "提示"
                    }, function(index) {
                        layer.close(index);
                        let loading = layer.load();
                        $.ajax({
                            url: DELETE_API,
                            data: data,
                            dataType: "json",
                            type: "post",
                            success: function(res) {
                                layer.close(loading);
                                if (res.code) {
                                    return layui.popup.failure(res.msg);
                                }
                                return layui.popup.success("操作成功", refreshTable);
                            }
                        })
                    });
                }

                // 刷新表格数据
                window.refreshTable = function() {
                    table.reloadData("data-table", {
                        scrollPos: "fixed",
                        done: function (res, curr) {
                            if (curr > 1 && res.data && !res.data.length) {
                                curr = curr - 1;
                                table.reloadData("data-table", {
                                    page: {
                                        curr: curr
                                    },
                                })
                            }
                        }
                    });
                }
            })

        </script>
    </body>
</html>
